<?php
namespace Common\Model;
use Common\Model\VRLiveModel;
class LiveVideoModel extends VRLiveModel
{
	
	protected $_validate = array(
		//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
	);


	/**
	 * 上传视频
	 */
	public function uploadVideo($info,$live_id = null, $is_vr = '0', $live_video_type = null){
		
		if(!$info) {// 上传错误提示错误信息
			var_dump($upload->getError());exit;
		}else{
			if($live_video_type == '1'){
				$files_name = "video1";
			}else{
				$files_name = "video2";
			}

			$videoName = $info[$files_name]['name'];
			$size = $info[$files_name]['size'];
			$ext = $info[$files_name]['ext'];
			$sha1 = $info[$files_name]['sha1'];
			$savename = C('UPLOADPATH').$info[$files_name]['savepath'].$info[$files_name]['savename'];
			$config = array('SecretId'       => C("API_SecretId"),
				'SecretKey'      => C("API_SecretKey"),
				'RequestMethod'  => 'POST',
				'DefaultRegion'  => C("API_DefaultRegion"));

			vendor("QcloudApi.QcloudApi");
			$service = \QcloudApi::load(\QcloudApi::MODULE_VOD, $config);
			//要输入的参数
			$package = array(
				'fileName' => $savename,                                              //文件的绝对路径，包含文件名
				'dataSize' => $size,                                          //分片大小，建议使用默认值5MB
				'isTranscode' => 1,                                                  //是否转码
				'isScreenshot' => 1,                                                 //是否截图
				'isWatermark' => 0,                                                  //是否添加水印
				//'notifyUrl' =>C("notify_url")."&type=2&live_video_type=".$live_video_type."&is_vr=".$is_vr."&key=".sha1(md5(".$live_id.")+"_xhw")              //转码完成后的回调地址，不转码此项无效
				'notifyUrl' =>$_SERVER['SERVER_NAME'].'/'.C("notify_url")."&type=2&live_video_type=".$live_video_type."&is_vr=".$is_vr."&key=".sha1(md5(".$live_id.")+"_xhw")  
				//'notifyUrl' =>"http://congcong.p.imooc.io/?key=123"	
			);
			$a = $service->MultipartUploadVodFile($package);
			\Think\Log::record('腾讯云返回：'.json_encode($a), 'INFO');
			if($a == false){
				return false;
				//return $this->error("调用腾讯云接口错误：".$service->getError()->getMessage());
			}else{

				$fileId = $a['fileId'];
				//删除本地文件
				unlink($savename);
				return $fileId;
			}
		}
	}
	
	public function get_video($fileName = null){
		$data = array();
		if($fileName){
			$config = array('SecretId'       => C("API_SecretId"),
					'SecretKey'      => C("API_SecretKey"),
					'RequestMethod'  => 'GET',
					'DefaultRegion'  => C("API_DefaultRegion"));
			vendor("QcloudApi.QcloudApi");
			$service = \QcloudApi::load(\QcloudApi::MODULE_VIDEO, $config);
			//要输入的参数
			//14651978969340560036
			$package = array(
					'fileName'=>$fileName
			);
			$data = $service->DescribeVodPlayInfo($package);
		}
		return $data;
	}
	
}

